<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    response.setHeader("cache-control","public");
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<!-- 试卷列表 -->
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/common.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/style.default.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/bootstrap-table.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/examMng/paperMng.css">
    <!--bootstrap基础引用 start-->
    <script type="text/javascript" src="<%=path%>/static/jstreeview/bootstrap/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="<%=path%>/static/js/bootstrap.min.js"></script>
    <!--bootstrap基础引用 end-->
    <!--bootstrap-dialog start-->
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.css">
    <script type="text/javascript" src="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.js"></script>
    <!--bootstrap-dialog end-->
</head>
<body>
<jsp:include page="../head.jsp" flush="true"/>
<!--body begin-->
<div class="main-container">
    <div class="container body-box" style="padding: 0px;">
        <div class="title-top" style="background: #4c4ca6;">
            <p>试卷列表：</p>
            <a class="btn btn-success addpaper" href="/examsys/paper/addOrEdit" style="background: #4c4ca6;border:solid 1px #ffffff;"><i
                    class="glyphicon glyphicon-plus-sign" ></i>新增试卷</a>
        </div>
        <div class="paper-content">
            <!--当前没有可用试卷 end-->
            <!--试卷列表-->
            <table id="table"></table>
        </div>
    </div>
</div>
<!--body end-->

<script type="text/javascript" src="<%=path%>/static/jquery/jquery-1.12.2.min.js"></script>
<script type="text/javascript" src="<%=path%>/static/js/bootstrap-table.js"></script>
<script type="text/javascript" src="<%=path%>/static/js/bootstrap-table-zh-CN.js"></script>
</body>

<script type="text/javascript">
    $(function () {
        // $('#topMain').children().eq(5).addClass('active'); // 追加样式;
        // $('#topMain').children().eq(5).children().attr('href', '#');

        // 试卷管理主页面
        if (${role eq 'master'}) {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        } else if (${role eq 'trainee'}) {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        } else {
            $('#topMain').children().eq(4).addClass('active'); // 追加样式;
            $('#topMain').children().eq(4).children().attr('href', '#');
        }



    })

    function doPost(to, p) {  // to:提交动作（action）,p:参数
        var myForm = document.createElement("form");
        myForm.method = "post";
        myForm.action = to;
        var myInput = document.createElement("input");
        myInput.setAttribute("name", "id");  // 为input对象设置name
        myInput.setAttribute("value", p);  // 为input对象设置value
        myForm.appendChild(myInput);
        document.body.appendChild(myForm);
        myForm.submit();
        document.body.removeChild(myForm);  // 提交后移除创建的form
    }


    function AddFunctionAlty(value, row, index) {

        if (row.status==1 && row.method=="auto") {
            return [
                '<button id="view",type="button" class="btn btn-default">预览</button> &nbsp;'
            ].join("");
        } else if (row.status==1 && row.method=="hand") {
            return [
                '<button id="view",type="button" class="btn btn-default">预览</button> &nbsp;'
            ].join("");
        } else {
            return [
                '<button id="edit",type="button" class="btn btn-default">编辑</button>&nbsp;' +
                '<button id="del",type="button" class="btn btn-default">删除</button>'
            ].join("");
        }
    }

    window.operateEvents = {
        'click #view': function (e, value, row, index) {

            javascript:doPost('/examsys/paper/pagePreview', row.id);

        }, 'click #edit': function (e, value, row, index) {

            javascript:doPost('/examsys/paper/addOrEdit', row.id);

        }, 'click #del': function (e, value, row, index) {
            $.ajax({
                type: "post",
                data: {
                    id: row.id
                },
                url: '/examsys/paper/delpaper',
                success: function (data) {
                    BootstrapDialog.confirm({
                        title : '提示',
                        message : '删除成功',
                        size : BootstrapDialog.SIZE_SMALL,
                        type : BootstrapDialog.TYPE_DEFAULT,
                        closable : true,
                        btnCancelLabel : '取消',
                        btnOKLabel : '确定'
                    });
                    $('#table').bootstrapTable('refresh', {
                        method : 'get',
                        dataType : 'json',
                        contentType : "application/x-www-form-urlencoded",
                        url: "<%=path%>/paper/dataList",
                        cache : false,
                    });
                }
            });
        }
    };

    $('#table').bootstrapTable({
        "pagination": true,
        "search": true,
        method: 'post',
        dataType: 'json',
        contentType: "application/x-www-form-urlencoded",
        url: '/examsys/paper/dataList',
        striped: false,
        toolbar: "#toolbar",
        showHeader: true,
        pageNumber: 1,
        showRefresh: true,                  //是否显示刷新按钮
        pagination : true,//是否分页
        sidePagination : 'client',//server:服务器端分页|client：前端分页
        pageSize : 4,//单页记录数
        pageList : [ 5, 10, 20, 30 ],//可选择单页记录数
        columns: [{
            field: 'number',
            title: '序号',
            align: "center",
            valign: "middle",
            formatter: function (value, row, index) {
                return index + 1;
            }
        }, {
            field: 'title',
            title: '试卷名称',
            align: "center",
            valign: "middle"
        }, {
            field: 'count',
            title: '试题数量',
            align: "center",
            valign: "middle"
        }, {
            field: 'score',
            title: '总分',
            align: "center",
            valign: "middle"
        }, {
            field: 'createtimeStr',
            title: '发布日期',
            valign: "middle"
        }, {
            field: 'status',
            title: '状态',
            align: "center",
            valign: "middle",
            formatter: function (value, row, index) {
                if(row.status==1){
                    return "已发布";
                } else {
                    return "未发布";
                }
            }
        }, {
            field: 'Operations',
            title: '操作',
            events: 'operateEvents',
            formatter: 'AddFunctionAlty',
            align: "center",
            valign: "middle"
        }],
    });

</script>

</html>
